package gui.mvc;

import java.util.ArrayList;
import java.util.List;

import api.Person;

/**
 * @author Ann Raboschuk
 */
public class Controller
{
   private List<Person> people;

   @SuppressWarnings("unchecked")
   public Controller()
   {
      people = new ArrayList<Person>();
      //loadAll();
   }

   public List<Person> getPeople()
   {
      return people;
   }

   public void deletePerson(int index)
   {
      //delete(people.get(index));
      people.remove(index);
   }

   public void editPerson(int index, String[] fields)
   {
      if (fields != null)
      {
         Person changedPerson = people.get(index);
         changedPerson.setSurname(fields[1]);
         changedPerson.setName(fields[2]);
         changedPerson.setAge(Integer.parseInt(fields[3]));
         changedPerson.setSex(fields[4].charAt(0));
         changedPerson.setEmail(fields[5]);
         changedPerson.setPhone(fields[6]);
         changedPerson.setAddress(fields[7]);
         
         //edit(changedPerson);
      }
   }

   public void addPerson(String[] fields)
   {
      if (fields != null)
      {
         Person person = new Person(fields[1], fields[2], Integer
               .parseInt(fields[3]), fields[4].charAt(0), fields[5], fields[6],
               fields[7]);
         people.add(person);
         //add(person);
      }
   }
}
